import { Page } from '@/base/Page';
import { ApkModel } from '@/base/model/apkModel';
import { getApkList, deleteApkItem, addApkVersion } from '@/base/api/apkApi';
import { getDeviceModelId } from '@/base/api/DeviceModelApi';
export class VersionBloc {
    model: any = {
        downloadUrl: '',
        upgradeType: 'PAD',
        versionCode: '',
        versionName: '',
        modifyContent: '',
        apkSize: '',
        extName: '',
        apkMd5: '',
        modelId: '',
        modelName: '',
        updateStatus: 1,
        detailedContent: ''
    };

    deveiceModel: any = {
        id: 0 || undefined,
        companyId: 0,
        isFirmware: true,
        isSelfMotion: true,
        isSoftware: true,
        modelIcon: '',
        modelName: '',
        sortId: 0,
        createTime: '',
        updateTime: ''
    };

    productList:any = ['PAD','VR']

    paged: Page<ApkModel> = new Page<ApkModel>([], 0, 1, 15, 0, []);
    loading = false;
    load(pageIndex: number, pageSize: number, modelId: number) {
        this.loading = true;
        let upgradeType=this.model.upgradeType
        return getApkList({
            pageIndex,
            pageSize,
            modelId,
            upgradeType
        }).then((res) => {
            this.paged = res.data;
        }).finally(() => {
            this.loading = false;
        });
    }
    removeItem(row: ApkModel) {
        this.loading = true;
        return deleteApkItem(row.id)
            .finally(() => {
                this.loading = false;
            });
    }
    addApkVersion(
        downloadUrl: string,
        apkSize: number,
        modifyContent: string,
        upgradeType: string,
        versionCode: number,
        versionName: string,
        modelId: number,
        updateStatus:number,
        detailedContent: string
        ) {
        return addApkVersion({ downloadUrl, apkSize, modifyContent, upgradeType, versionCode, versionName, modelId, updateStatus,detailedContent })
    }

    getModel(id: number) {
        this.loading = true;
        return getDeviceModelId({id}).then((res) => {
            this.deveiceModel = res.data
            this.model.modelName = res.data.modelName || ''
            return res;
        }).finally(() => {
            this.loading = false;
        });
    }

}
